package cn.kgc.kgde.bookstore.controller;

import cn.kgc.kgde.bookstore.entity.Book;
import cn.kgc.kgde.bookstore.entity.Category;
import cn.kgc.kgde.bookstore.entity.ResultInfo;
import cn.kgc.kgde.bookstore.service.CategoryService;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author myt
 * @since 2022-05-23
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    /*树形json格式数据*/
    @PostMapping(value = "getTree")
    public ResultInfo getTreeByPid(Long id) {
        List<Category> category= categoryService.getTree(id);
        return new ResultInfo(200,"分类",category);
    }

    //添加分类
    @PostMapping("/addCategory/{cateName}/{cateParentId}")
    public ResultInfo addCategory(@PathVariable String cateName, @PathVariable Long cateParentId) {
        System.out.println(cateName+"cateName");
        System.out.println(cateParentId+"cateParentId");
        categoryService.addCategory( cateName,cateParentId );
        return new ResultInfo(200,"分类添加成功！");
    }

    /*
    * 删除分类
    * */
    @GetMapping("/removeCategory")
    public ResultInfo removeCategory(Long cateId) {
        System.out.println(cateId+"cateParentId");
        categoryService.removeCategory( cateId );
        return new ResultInfo(200,"已删除！");
    }
}
